﻿import mx.utils.Delegate;
//import crl.toolTip;
class crl.toolTip {
	private var _parent_mc:MovieClip;
	//父MC 
	private var _mc:MovieClip;
	//Tip MC 
	private var _obj:Object;
	//Tip 的对象 
	private var _bg_mc:MovieClip;
	//背景 
	private var _shadow_mc:MovieClip;
	//背景阴影 
	private var _shadow_color:Color;
	private var _text_txt:TextField;
	//Tip文本 
	private var _txt:String;
	//Tip文本内容 
	private var _type:String;
	private var text_x:Number;
	private var text_y:Number;
	private var text_w:Number;
	private var text_h:Number;
	private var i:Number;
	private var intervalID:Number;
	private var intervalID2:Number;
	private var intervalID3:Number;
	private var showing:Boolean;
	private var mTextFormat:TextFormat;
	public function toolTip() {
		i = 0;
		showing = false;
		mTextFormat = new TextFormat();
		mTextFormat.font="Verdana";
		mTextFormat.color=0xffffff;
	}
	function newTip(obj:Object, tipText:String) {
		_parent_mc = _root;
		if (_root._parent) {
			_parent_mc = _root._parent;
		}
		_obj = obj;
		_txt = tipText;
		if (obj instanceof Button) {
			_type = "Button";
		} else if (obj instanceof MovieClip) {
			_type = "MovieClip";
		}
		_obj.useHandCursor=false;//不让手形出现;
		_obj.onRollOver = Delegate.create(this, show);
		_obj.onPress = _obj.onReleaseOutside=_obj.onRollOut=Delegate.create(this, hide);
	}
	function count() {
		i++;
		if (i>=3 && showing == false) {
			showing = true;
			_parent_mc.createEmptyMovieClip("myTip", _parent_mc.getNextHighestDepth());
			_mc = _parent_mc.myTip;
			_mc._alpha = 0;
			_mc._x = _parent_mc._xmouse-40;
			_mc._y = _parent_mc._ymouse-10;
			// drowTXT 
			_mc.createTextField("myTextField", 3, 0, 0, 200, 100);
			_text_txt = _mc.myTextField;
			_text_txt.text = _txt;
			_text_txt.setTextFormat(mTextFormat)
			_text_txt.wordWrap = true;
			_text_txt.selectable = false;
			_text_txt.multiline = true;
			_text_txt.font="Verdana";
			text_w = _text_txt.textWidth;
			text_h = _text_txt.textHeight;
			if (_mc._x+text_w+8>Stage.width) {
				_text_txt._x = Stage.width-text_w-_mc._x-8;
			} else if (_mc._x-8<0) {
				_text_txt._x = 8-_mc._x;
			}
			text_x = _text_txt._x;
			text_y = _text_txt._y=-text_h;
			_text_txt._visible = false;
			//drowBG 
			_bg_mc = _mc.createEmptyMovieClip("bar", 2);
			var mx:Number = _bg_mc._xmouse;
			var my:Number = _bg_mc._ymouse;
			if (Stage.width-_parent_mc._xmouse<15) {
				mx -= 15;
			}
			_bg_mc.beginFill(0x999999, 30);
			_bg_mc.lineStyle(1, 0x000000, 80);
			_bg_mc.moveTo(mx, 5);
			_bg_mc.lineTo(mx, 15);
			_bg_mc.lineTo(mx+10, 5);
			_bg_mc.lineTo(text_x+text_w+5, 5);
			_bg_mc.lineTo(text_x+text_w+5, -text_h);
			_bg_mc.lineTo(text_x-5, -text_h);
			_bg_mc.lineTo(text_x-5, 5);
			_bg_mc.lineTo(mx, 5);
			_bg_mc.endFill();
			_shadow_mc = _bg_mc.duplicateMovieClip("_mask_mc", 1, {_x:2, _y:2, _alpha:30});
			_shadow_color = new Color(_shadow_mc);
			_shadow_color.setRGB(0x000000);
			_obj.onMouseMove = hide;
			intervalID2 = setInterval(this, "fadeIn", 10);
			// intervalID3 = setInterval (this, "hide", _txt.length * 200) 他的这句在这边改到下面那句;
			intervalID3 = setInterval(this, "hide", 2000);
		} else if (!_obj._name) {
			hide();
		} else {
			_obj.onMouseMove = function() {
				i = 0;
			};
		}
	}
	function fadeIn() {
		if (_mc._alpha<100) {
			_mc._alpha += 5;
		} else {
			clearInterval(intervalID2);
			_text_txt._visible = true;
		}
	}
	function show() {
		Mouse.hide();//不看光标
		intervalID = setInterval(this, "count", 300);
	}
	function hide() {
		Mouse.show();//看光标
		_mc.removeMovieClip();
		clearInterval(intervalID);
		clearInterval(intervalID2);
		clearInterval(intervalID3);
		showing = false;
		i = 0;
		_obj.onMouseMove = null;
	}
	static function showTip(obj:Object, tipText:String) {
		var myTip:toolTip = new toolTip();
		myTip.newTip(obj, tipText);
	}
}
